package com.ylzinfo.jck.config;


import com.ylzinfo.jck.services.JckWS;
import com.ylzinfo.jck.services.JckWSImpl;
import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.xml.ws.Endpoint;

/**
 * @author sunqy
 * @create 2019/12/31
 */

@Configuration
public class CxfConfig {

    @Value("${cxf.endpoint}")
    private String cxfEndpoint;

    @Bean
    public ServletRegistrationBean cxfDispatcherServlet() {
        return new ServletRegistrationBean(new CXFServlet(),"/services/*");
    }

    @Bean(name = Bus.DEFAULT_BUS_ID)
    public SpringBus springBus() {
        return new SpringBus();
    }

    @Bean
    public JckWS jckService() {
        return new JckWSImpl();
    }

    @Bean
    public Endpoint endpoint() {
        EndpointImpl endpoint = new EndpointImpl(springBus(), jckService());
        endpoint.publish(cxfEndpoint);
        return endpoint;
    }

}
